/* @(#)GSBusOrderCanceSubmitAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-3-18
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.text.SimpleDateFormat;
import java.util.HashMap;

import system.LoginContext;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.business.GSUniteGwProcessor;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;

/**
 * 更新巴士物资订单取消
 */
public class GSBusOrderCanceSubmitAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {
        String tOrderid = aForm.getRequest().getParameter("orderid");
        String tContents = aForm.getRequest().getParameter("contents");
        String tStatus = aForm.getRequest().getParameter("status");
        String sign = aForm.getRequest().getParameter("sign");
        String tIsTradeFlatManuf = aForm.getRequest().getParameter("isTradeFlatManuf");
        String tIsTradeFlatProv = aForm.getRequest().getParameter("isTradeFlatProvider");
        
        LoginContext context = (LoginContext)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String buf = df.format(new java.util.Date(System.currentTimeMillis()));
        String tOrderDetailStatus=null;
        if(tStatus.equals(GSBaseConstants.ORDER_AUTHORISE)){
             tOrderDetailStatus = GSBaseConstants.ORDER_CANCEL;
        }
        else
        {
        	//已确认的订单有取消申请操作，订货中的订单取消操作和原来不变
        	if (tStatus.equalsIgnoreCase(GSBaseConstants.ORDER_ORDER_CONFIRM))	//已确认
        		tOrderDetailStatus = GSBaseConstants.ORDER_APPLAY_CANCEL;
        	else																//订货中
        		tOrderDetailStatus = GSBaseConstants.ORDER_BLANK_OUT;
        }
        try{
            boolean tFlag = GSOrderProcessor.modifyCancelBusOrderTask(tStatus,tOrderDetailStatus,tOrderid,context,buf,tContents,tIsTradeFlatManuf,tIsTradeFlatProv,sign);
            if(tFlag){
                aForm.getRequest().setAttribute("message","订单取消执行成功");
            }else{
                aForm.getRequest().setAttribute("message","订单取消执行失败");
            }
        }catch(GSException ge){
            aForm.getRequest().setAttribute("message","订单取消执行失败");
            aForm.getRequest().setAttribute("window","true");
            throw ge;
        }catch(Exception e){
            aForm.getRequest().setAttribute("message","订单取消执行失败");
            aForm.getRequest().setAttribute("window","true");
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10044,GSException.E10044_MSG);
        }
        //巴士物资级操作员可操作订货单位及送货地址
        GSUniteGwProcessor unitePro=new GSUniteGwProcessor();
        aForm.getRequest().setAttribute("orderdept",unitePro.getWareHouseLevelName(context.getLoginWarehouseCode(), context.getLoginWarehouseCode()));
        //种类等级
        GSManufactureProcessor tGSManufProcessor = new GSManufactureProcessor();
        tGSManufProcessor.getManufactureOfLevel(aForm);
        
        aForm.getRequest().setAttribute("requery","true");
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
